//
//  FreightInformationViewController.m
//  Globalstone
//
//  Created by 辰领科技 on 16/7/11.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "FreightInformationViewController.h"

@interface FreightInformationViewController ()
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;//司机名称
@property (strong, nonatomic) IBOutlet UILabel *LicensePlateNumberLabel;//车牌号码
@property (strong, nonatomic) IBOutlet UILabel *locationLabel;//车辆位置
@property (strong, nonatomic) IBOutlet UILabel *phoneNumberLabel;//联系电话
@property (strong, nonatomic) IBOutlet UILabel *deliveryTimeLabel;//送货时间
@property (strong, nonatomic) IBOutlet UILabel *estimatedTimeLabel;//预计送货时间
@property (strong, nonatomic) IBOutlet UILabel *deliveryTimelabel;//到达时间
@property (strong, nonatomic) IBOutlet UILabel *stateLabel;//交货状态


@end

@implementation FreightInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initViewLayout];
    if ([_type isEqualToString:@"1"]) {
        [self getOrderImportTruckDetail];
    }else{
        [self getOrderExportTruckDetail];
    }
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    self.view.backgroundColor = [UIColor colorWithWhite:0.941 alpha:1.000];
    self.scroview.contentSize = flexibleSize(CGSizeMake(320, 505), NO);
    
}

- (IBAction)back:(id)sender {
    [self backBtn];
}



#pragma mark === 进口货运信息
- (void)getOrderImportTruckDetail{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_indentId forKey:@"oimpId"];
    
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryOrderImportTruckDetail withHttpType:@"POST" withTag:GS_GS_queryOrderImportTruckDetail];
}


#pragma mark === 出口货运信息
- (void)getOrderExportTruckDetail{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_indentId forKey:@"oexpId"];
    
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryOrderExportTruckDetail withHttpType:@"POST" withTag:GS_GS_queryOrderExportTruckDetail];
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==GS_GS_queryOrderImportTruckDetail || tag == GS_GS_queryOrderExportTruckDetail) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            if ([database[@"result"]isEqual:[NSNull null]]) {
                return;
            }
            NSDictionary * dic = database[@"result"];
            if ([_type isEqualToString:@"2"]) {//出口
                NSArray * array = @[@"待托运",@"托运中",@"待上船",@"海运中",@"已提单"];
                _stateLabel.text =  array[[[NSString stringWithFormat:@"%@",dic[@"status"]]integerValue]-1];
                  _locationLabel.text = [NSString stringWithFormat:@"%@",dic[@"adress"]];
                dic = dic[@"truck"];
                _nameLabel.text = [NSString stringWithFormat:@"%@",dic[@"oetrName"]];
                _LicensePlateNumberLabel.text = [NSString stringWithFormat:@"%@",dic[@"oetrNo"]];
              
                _phoneNumberLabel.text = [NSString stringWithFormat:@"%@",dic[@"oetrPhone"]];
                _deliveryTimeLabel.text =  [NSString stringWithFormat:@"%@",dic[@"oetrLoadTimePlan"]];
                _deliveryTimelabel.text =  [NSString stringWithFormat:@"%@",dic[@"oetrArriveTimePlan"]];
                _estimatedTimeLabel.text =  [NSString stringWithFormat:@"%@",dic[@"dateTime"]];
                
            }else{
                NSArray * array = @[@"待订舱",@"待装柜",@"待上船",@"海运中",@"待通关",@"待托运",@"待收货",@"交易完成"];
                _stateLabel.text =  array[[[NSString stringWithFormat:@"%@",dic[@"OrderStatus"]]integerValue]-1];
                dic = dic[@"ImportTruck"];
                _nameLabel.text = [NSString stringWithFormat:@"%@",dic[@"oiruName"]];
                _LicensePlateNumberLabel.text = [NSString stringWithFormat:@"%@",dic[@"oiruCarNo"]];
                _locationLabel.text = [NSString stringWithFormat:@"%@",dic[@"adress"]];
                _phoneNumberLabel.text = [NSString stringWithFormat:@"%@",dic[@"oiruPhone"]];
                _deliveryTimeLabel.text =  [NSString stringWithFormat:@"%@",dic[@"oiruSendTimePlan"]];
                _deliveryTimelabel.text =  [NSString stringWithFormat:@"%@",dic[@"oiruArriTime"]];
                _estimatedTimeLabel.text =  [NSString stringWithFormat:@"%@",dic[@"DateTime"]];
              
            }
            
            
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}



@end
